<template>
    <div>
          <Row class="formRow">
            <Col span="2" class="rightRow">
            <span class="ModelInputTitle">订单ID</span>
            </Col>
            <Col span="2" class="leftRow">
              <Input v-model="formInline.orderId" placeholder="订单ID" clearable style="width: 100%" size="large"></Input>
            </Col>
            <Col span="2" class="rightRow">
              <span class="ModelInputTitle">医院名称</span>
            </Col>
            <Col span="2" class="leftRow">
              <Input v-model="formInline.hospitalName" placeholder="医院名称" clearable style="width: 100%x" size="large"></Input>
            </Col>
            <Col span="2" class="rightRow">
              <span class="ModelInputTitle">患者名称</span>
            </Col>
            <Col span="2" class="leftRow">
              <Input v-model="formInline.patientName" placeholder="患者名称" clearable style="width: 100%" size="large"></Input>
            </Col>
            <Col span="2" class="rightRow">
              <span class="ModelInputTitle" style="width: 100%;text-align: right">患者手机号</span>
            </Col>
            <Col span="2" class="leftRow">
              <Input v-model="formInline.patientPhone" placeholder="患者手机号" clearable style="width: 100%" size="large"></Input>
            </Col>
            <Col span="2" class="rightRow">
              <span class="ModelInputTitle">护士名称</span>
            </Col>
            <Col span="2" class="leftRow">
              <Input v-model="formInline.nurseName" placeholder="护士名称" clearable style="width: 100%" size="large"></Input>
            </Col>
            <Col span="2" class="rightRow">
              <span class="ModelInputTitle" style="width: 100%;text-align: right">物流人员名称</span>
            </Col>
            <Col span="2" class="leftRow">
              <Input v-model="formInline.receiveName" placeholder="物流人员名称" clearable style="width: 100%" size="large"></Input>
            </Col>

          </Row>
          <Row class="formRow" style="margin-top: 20px">
            <Col span="2" class="rightRow">
            <span class="ModelInputTitle">标本类型</span>
            </Col>
            <Col span="4" class="leftRow">
            <Select  size="large" style="width:100%" v-model="formInline.specimenType">
              <Option v-for="s in specimenTypeArr" :key="s.id"  :value="s.dataCode" >{{s.dataName}}</Option>
            </Select>
            </Col>
            <Col span="2" class="rightRow">
              <span class="ModelInputTitle" style="width: 100%;text-align: right">标本条形码</span>
            </Col>
            <Col span="4" class="leftRow">
              <Input v-model="formInline.specimenBarcode" placeholder="标本条形码" clearable style="width: 100%" size="large"></Input>
            </Col>
            <Col span="2" class="rightRow">
              <span class="ModelInputTitle" style="width:100%;text-align: right">送检中心条形码</span>
            </Col>
            <Col span="4" class="leftRow">
              <Input v-model="formInline.testcenterBarcode" placeholder="送检中心条形码" clearable style="width: 100%" size="large"></Input>
            </Col>

            <Col span="2" class="rightRow">
              <span class="ModelInputTitle" style="width: 100%;text-align: right">标本是否有效</span>
            </Col>
            <Col span="4" class="leftRow">
              <Select  size="large" style="width:100%" v-model="formInline.isEffective">
                <Option  value="1" >是</Option>
                <Option  value="0" >否</Option>
              </Select>
            </Col>
          </Row>
          <Row  class="formRow" style="margin-top: 20px">
            <Col span="2" class="rightRow">
            <span class="ModelInputTitle" style="width: 100%;text-align: right">标本接受开始时间</span>
            </Col>
            <Col span="4" class="leftRow">
            <DatePicker type="date" size="large" placeholder="标本接受开始时间" style="width: 100%" v-model="formInline.receiveTimeStart"></DatePicker>
            </Col>
            <Col span="2" class="rightRow">
            <span class="ModelInputTitle" style="width: 100%;text-align: right">标本接受结束时间</span>
            </Col>
            <Col span="4" class="leftRow">
            <DatePicker type="date" size="large" placeholder="标本接受开始时间" style="width: 100%" v-model="formInline.receiveTimeEnd"></DatePicker>
            </Col>
            <Col span="4" class="leftRow">
            <Button type="primary" @click="onSubmit">查询</Button>
            <Button type="primary" @click="resetForm">重置</Button>
            </Col>
          </Row>



      <Table :data="tableData" :columns="cloums" stripe :loading="loading"  style="margin-top: 20px"></Table>
      <div style="margin: 10px;overflow: hidden">
        <div style="float: right;">
          <Page :total="total" :placement="placement" :current="1" @on-change="changePage" show-total show-elevator show-sizer @on-page-size-change="changeSize"></Page>
        </div>
      </div>

      <Modal
        v-model="orderPicModal"
        title="申请单照片" width="600">
        <img :src="orderUrl" alt="" style="width: 100%">
        <div slot="footer">
        </div>
      </Modal>
    </div>
</template>
<script type="text/ecmascript-6">
  import axios from "axios"
    export default {
        data() {
            return {
              formInline:{
                orderId:"",
                hospitalName:"",
                patientName:"",
                patientPhone:"",
                nurseName:"",
                receiveName:"",
                specimenBarcode:"",
                testcenterBarcode:"",
                specimenType:"",
                isEffective:"",
                receiveTimeStart:"",
                receiveTimeEnd:""
              },
              page:1,
              pageSize:10,
              placement:"bottom",
              orderUrl:"",//申请单照片
              orderPicModal:false,//申请单照片模态框
              specimenTypeArr:[],
              tableData:[],
              loading:true,
              total:0,
              cloums:[
                {
                  title: '订单ID',
                  key: 'orderId',
                  width:100,
                  align:"center"
                },
                {
                  title: '标本条形码',
                  key: 'specimenBarcode',
                  width:120,
                  align:"center"
                },
                {
                  title: '医院ID',
                  key: 'hospitalId',
                  width:100,
                  align:"center"
                },
                {
                  title: '患者ID',
                  key: 'patientId',
                  width:100,
                  align:"center"
                },
                {
                  title: '患者名称',
                  key: 'patientName',
                  width:100,
                  align:"center"
                },
                {
                  title: '性别',
                  key: 'sex',
                  width:60,
                  align:"center"
                },
                {
                  title: '年龄',
                  key: 'age',
                  width:60,
                  align:"center"
                },
                {
                  title: '年龄单位',
                  key: 'ageUnit',
                  width:100,
                  align:"center"
                },
                {
                  title: '标本类型',
                  key: 'specimenType',
                  width:100,
                  align:"center"
                },
                {
                  title: '床号',
                  key: 'bedNo',
                  width:60,
                  align:"center"
                },
                {
                  title: '住院号',
                  key: 'hospitalizeNo',
                  width:80,
                  align:"center"
                },
                {
                  title: '科室',
                  key: 'hospitalSubject',
                  width:80,
                  align:"center"
                },
                {
                  title: '标本性状',
                  key: 'specimenCharacter',
                  width:100,
                  align:"center"
                },
                {
                  title: '护士名称',
                  key: 'nurseName',
                  width:100,
                  align:"center"
                },
                {
                  title: '采集时间',
                  key: 'collectTime',
                  width:150,
                  align:"center"
                },
                {
                  title: '接收人员名称',
                  key: 'receiveName',
                  width:120,
                  align:"center"
                },
                {
                  title: '接收时间',
                  key: 'receiveTime',
                  width:150,
                  align:"center"
                },
                {
                  title: '临床印象',
                  key: 'clinicalImpression',
                  width:100,
                  align:"center"
                },
                {
                  title: '送检中心条码',
                  key: 'testcenterBarcode',
                  width:120,
                  align:"center"
                },
                {
                  title: '送检中心ID',
                  key: 'testcenterId',
                  width:100,
                  align:"center"
                },
                {
                  title: '标本是否有效',
                  key: 'isEffective',
                  width:120,
                  align:"center"
                },
                {
                  title: '病人电话',
                  key: 'patientPhone',
                  width:120,
                  align:"center"
                },
                {
                  title: '报告是否回传',
                  key: 'reportBack',
                  width:120,
                  align:"center"
                },
                {
                  title: '预计回传时间',
                  key: 'backTime',
                  width:150,
                  align:"center"
                },
                {
                  title: '报告回传结果类型',
                  key: 'resultType',
                  width:140,
                  align:"center"
                },
                {
                  title: '检测时间',
                  key: 'checkTime',
                  width:150,
                  align:"center"
                },
                {
                  title: '创建人',
                  key: 'creater',
                  width:80,
                  align:"center"
                },
                {
                  title: '修改人',
                  key: 'updater',
                  width:80,
                  align:"center"
                },
                {
                  title: '申请单照片',
                  width:100,
                  align:"center",
                  fixed:"right",
                  render:(h,params)=>{
                    return h("div",[
                      h("A",{
                       style:{
                         color:"#57a3f3"
                       },
                        on:{
                          click:()=>{
                            console.log(params.row.orderUrl)
                            if(params.row.orderUrl){
                              this.orderUrl = params.row.orderUrl;
                              this.orderPicModal = true;
                            }else{
                              this.$Notice.info({title:"暂无申请单照片"});
                            }
                          }
                        }
                      },"查看")
                    ])
                  }
                },
              ]
            }
        },
      mounted(){
          this.getSpecimenType();
          this.init();
      },
      methods:{
        getSpecimenType(){
          var qs = require("qs");
          var param = qs.stringify({
            dictType:"specimen_type"
          })
          axios.post("/common/dictDataList",param).then((res)=>{
              if(res.data.code == "000000"){
                this.specimenTypeArr = res.data.data;
              }else{
                this.$Notice.error({title:res.data.msg});
              }
          });
        },
        init(){
          var qs = require("qs");
          var param = qs.stringify({
            page:this.page,
            pageSize:this.pageSize,
            orderId:this.formInline.orderId,
            hospitalName:this.formInline.hospitalName,
            specimenBarcode:this.formInline.specimenBarcode,
            specimenType:this.formInline.specimenType,
            patientName:this.formInline.patientName,
            nurseName:this.formInline.nurseName,
            receiveName:this.formInline.receiveName,
            testcenterBarcode:this.formInline.testcenterBarcode,
            isEffective:this.formInline.isEffective,
            patientPhone:this.formInline.patientPhone,
            receiveTimeStart:this.formInline.receiveTimeStart,
            receiveTimeEnd:this.formInline.receiveTimeEnd
          });
          axios.defaults.headers.common['Authorization'] = sessionStorage.getItem("token");
          axios.post("/specimen/queryBusSpecimenListByPage",param).then((res)=>{
            console.log(res.data);
            if(res.data.code == "000000"){
                this.loading = false;
                this.total = res.data.count;
                for(var i = 0;i<res.data.data.length;i++){
                  res.data.data[i].collectTime =  res.data.data[i].collectTime==null?"":this.format(res.data.data[i].collectTime);//采集时间
                  res.data.data[i].receiveTime =  res.data.data[i].receiveTime==null?"":this.format(res.data.data[i].receiveTime);//接受时间
                  res.data.data[i].checkTime =  res.data.data[i].checkTime==null?"":this.format(res.data.data[i].checkTime);//检测时间
                  res.data.data[i].backTime =  res.data.data[i].backTime==null?"":this.format(res.data.data[i].backTime);//预计回传时间
                  res.data.data[i].reportBack = res.data.data[i].reportBack=="1"?"是":"否";//报告是否回传
                  res.data.data[i].isEffective = res.data.data[i].isEffective=="1"?"是":"否";//标本是否有效
                  res.data.data[i].sex = res.data.data[i].sex=="1"?"男":"女";//性别
                  res.data.data[i].resultType = res.data.data[i].resultType=="1"?"化验报告":"物理报告";//报告回传结果类型
                  for(let j=0;j<this.specimenTypeArr.length;j++){
                    if(res.data.data[i].specimenType==this.specimenTypeArr[j].dataCode){
                      res.data.data[i].specimenType = this.specimenTypeArr[j].dataName;
                    }
                  }
                  if(res.data.data[i].hospitalSubject=="01"){
                    res.data.data[i].hospitalSubject = "全科";
                  }else if(res.data.data[i].hospitalSubject=="02"){
                    res.data.data[i].hospitalSubject = "内科"
                  }else if(res.data.data[i].hospitalSubject=="03"){
                    res.data.data[i].hospitalSubject = "外科"
                  }else if(res.data.data[i].hospitalSubject=="04"){
                    res.data.data[i].hospitalSubject = "儿科"
                  }else if(res.data.data[i].hospitalSubject=="05"){
                    res.data.data[i].hospitalSubject = "妇科"
                  }
                }
                this.tableData = res.data.data;
            }else{
              this.$Notice.error({title:res.data.msg})
            }
          })
        },
        format(date){
          var d = new Date(date);
          var year = d.getFullYear();
          var month = parseInt(d.getMonth())+1>9?parseInt(d.getMonth())+1:"0"+(parseInt(d.getMonth())+1);
          var day = d.getDate()>9?d.getDate():"0"+d.getDate();
          var h = d.getHours()>9?d.getHours():"0"+d.getHours();
          var m =  d.getMinutes()>9?d.getMinutes():"0"+d.getMinutes();
          var s = d.getSeconds()>9?d.getSeconds():"0"+d.getSeconds();
          return year+"-"+month+"-"+day+" "+h+":"+m+":"+s;
        },
        onSubmit(){
          this.init();
        },
        resetForm(){
            this.formInline.orderId = "";
            this.formInline.hospitalName = "";
            this.formInline.patientName = "";
            this.formInline.patientPhone = "";
            this.formInline.nurseName = "";
            this.formInline.receiveName = "";
            this.formInline.specimenBarcode = "";
            this.formInline.testcenterBarcode = "";
            this.formInline.specimenType = "";
            this.formInline.isEffective = "";
            this.formInline.receiveTimeStart = "";
            this.formInline.receiveTimeEnd = "";
            },
        changePage(page){
          this.page = page;
          this.loading = true;
          this.init();
        },
        changeSize(size){
          this.placement = size>=20?"top":"bottom";
          this.pageSize = size;
          this.loading = true;
          this.init();
        }
      }
    }
</script>
